﻿@inherits BaseForm<JxAccountHead>

<AccountHeadTypeForm Form="Model" ShowAction>
    <AntRow>
        <DataItem Span="8" Label="对账单号" Required>
            <AntInput Disabled @bind-Value="@context.AccountNo" />
        </DataItem>
        <DataItem Span="8" Label="单证状态">
            <KTag Text="@context.Status" />
        </DataItem>
        <DataItem Span="8" Label="对账日期" Required>
            <AntDatePicker @bind-Value="@context.AccountDate" />
        </DataItem>
    </AntRow>
    <AntRow>
        <DataItem Span="8" Label="商业伙伴" Required>
            <PartnerPicker Value="@context.Partner" AllowClear Type="@context.Type"
                           ValueChanged="e=>context.Partner=e?.ToString()" />
        </DataItem>
        <DataItem Span="8" Label="业务日期" Required>
            <AntRangePicker @bind-RangeValue="@context.BizDates" />
        </DataItem>
        <DataItem Span="8" Label="总金额">
            <AntDecimal @bind-Value="@context.TotalAmount" /> 元
        </DataItem>
    </AntRow>
    <AntRow>
        <DataItem Span="8" Label="合同号">
            <AntInput @bind-Value="@context.ContractNo" />
        </DataItem>
        <DataItem Span="8" Label="发票号">
            <AntInput @bind-Value="@context.InvoiceNo" />
        </DataItem>
    </AntRow>
    <AntRow>
        <DataItem Span="24" Label="备注">
            <AntTextArea @bind-Value="@context.Note" />
        </DataItem>
    </AntRow>
    <AntRow>
        <DataItem Span="24" Label="附件">
            <KUpload @ref="upload" ReadOnly="Model.IsView" Value="@context.Files"
                     IsButton="!Model.Data.IsNew" OnFilesChanged="OnFilesChangedAsync" />
        </DataItem>
    </AntRow>
</AccountHeadTypeForm>

@code {
    private KUpload upload;

    private async Task OnFilesChangedAsync(List<FileDataInfo> files)
    {
        if (Model.Data.IsNew)
        {
            Model.Files[nameof(JxAccountHead.Files)] = files;
        }
        else
        {
            Model.Files[nameof(JxAccountHead.Files)] = files;
            await Model.SaveAsync(d => upload.SetValueAsync(d.Files), false);
        }
    }
}